<template>
  <div>

    <q-layout>
      <q-layout-header ref="header">
        <xheader :title="title"></xheader>
      </q-layout-header>
      <q-page-container>

        <q-page padding>

          <q-input ref="code" float-label="坩埚条码" v-model="code" clearable
                   @blur="searchBatchInfo"
                   @keydown.enter="searchBatchInfo" :after="$parent.getScanIcon('code',this)"/>
          <q-input float-label="坩埚信息" placeholder="请输入坩埚条码" readonly v-model="codeInfo" type="textarea" rows="4"
                   hide-underline/>
          <q-input ref="facCode" float-label="喷涂设备编码" v-model="facCode" clearable
                   @blur="getFacilitiesInfo" :after="$parent.getScanIcon('facCode',this)"
                   @keydown.enter="getFacilitiesInfo"/>
          <q-input float-label="设备信息" placeholder="请输入喷涂设备编码" readonly v-model="facInfo" type="textarea" rows="3"
                   hide-underline/>
          <q-select
            v-model="diban"
            float-label="底板"
            :readonly="!isCreate"
            :options="dibanInfo" clearable
          />
          <q-input placeholder="备注" v-model="description" type="textarea" rows="3"/>
          <br>
          <q-btn label="提交" color="primary" class="full-width" @click="submit"/>
        </q-page>

      </q-page-container>
    </q-layout>
  </div>
</template>

<script>

import utils from '../../js/utils'
import Xheader from '../../components/xheader'

export default {
  name: 'ganguo_spray',
  components: { Xheader },
  props: {
    title: {}
  },
  data: () => ({
    code: '',
    codeInfo: '',
    facCode: '',
    facInfo: '',
    facId: '',
    ggBatchNo: '',
    diban: '',
    dibanInfo: [],
    isCreate: true,
    description: ''
  }),
  methods: {
    submit () {
      if (!this.ggBatchNo) {
        this.$parent.info('坩埚条码不能为空！')
        return
      }
      if (!this.facId) {
        this.$parent.info('喷涂设备不能为空！')
        return
      }
      if (!this.diban) {
        this.$parent.info('底板不能为空！')
        return
      }
      this.axios.post(this.$conf.server + '/useMaterial/ganguoSpray', this.$qs.stringify({
        facId: this.facId,
        batchNo: this.ggBatchNo,
        diban: this.diban,
        desc: this.description
      })).then(res => {
        this.$parent.info(res.data.msg)
        if (res.data.result) {
          this.ggBatchNo = ''
          this.facId = ''
          this.code = ''
          this.facCode = ''
          this.codeInfo = ''
          this.facInfo = ''
          this.description = ''
        }
      })
    },
    popupFilter () {

    },
    searchBatchInfo () {
      if (this.code !== '') {
        this.axios.post(this.$conf.server + '/useMaterial/getMaterialInfo', this.$qs.stringify({
          batchNo: this.batchNo, storckCheck: false
        })).then(res => {
          if (res.data.result) {
            this.batchId = res.data.ID
            this.sgdModel = res.data.CUT_METHOD
            this.codeInfo = '规格：' + utils.nvl(res.data.CUT_METHOD) +
                '\r\n产品名称：' + utils.nvl(res.data.PNAME) +
                '\r\n配方名称：' + utils.nvl(res.data.PFNAME) + '(' + utils.nvl(res.data.VERSION) + ')' +
                (res.data.IS_TEST === 'Y' ? '\r\n<span style=\'color: #f00;\'>试验件</span>' : '') +
                '\r\n' + utils.nvl(res.data.DESCRIPTION)

            this.ggBatchNo = this.batchNo
            this.codeInfo = utils.nvl(res.data.PCODE) + '，' + utils.nvl(res.data.PNAME) +
                (res.data.VERDORCODE ? '\r\n供应商：' + utils.nvl(res.data.VERDORCODE) + '-' + utils.nvl(res.data.VERDORNAME) : '') +
                '\r\n' + utils.nvl(res.data.DESCRIPTION)
            // 显示已喷涂坩埚信息
            if (res.data.ganguoInfo) {
              this.facCode = res.data.ganguoInfo.FACCODE
              if (res.data.ganguoInfo.FACNAME != null) {
                this.facInfo = utils.nvl('设备名称：' + res.data.ganguoInfo.FACNAME + ',设备编码：' + res.data.ganguoInfo.FACCODE)
              }
              this.diban = res.data.ganguoInfo.DIBANCODE
              if (res.data.ganguoInfo.STATUS !== 'CREATE') {
                this.isCreate = false
                this.description = '此坩埚已喷涂！'
              } else {
                this.isCreate = true
                this.description = ''
              }
            }
          } else {
            this.$parent.info(res.data.msg)
          }
        })
      }
    },
    getFacilitiesInfo () {
      this.axios.post(this.$conf.server + '/manuBatch/getFacilitiesInfo', this.$qs.stringify({ code: this.facCode })).then(res => {
        // this.eqxx = res.data
        if (res.data.result) {
          if (res.data.FANCILITY_TYPE !== 'PT') {
            this.$parent.info('不是坩埚喷涂设备！')
          } else {
            res.data.FANCILITY_TYPE = '坩埚喷涂'
          }
          this.facId = res.data.EMES_FACILITIES_ID
          this.facInfo = utils.nvl('设备名称：' + res.data.NAME + ',设备编码：' + res.data.CODE)
        } else {
          this.$parent.info(res.data.msg)
        }
      })
    },
    initDiban () {
      this.axios.post(this.$conf.server + '/manuPrepare/getDibanList', {}).then(res => {
        if (res.data.result) {
          for (let v of res.data.facListDB) {
            this.dibanInfo.push({ value: v.FACID, label: v.FACCODE })
          }
        }
      }
      )
    }
  },
  created () {
    this.initDiban()
  }
}
</script>

<style scoped>

</style>
